The capacity achieving probability mass function (PMF) of a finite signal constellation with an average power constraint is in most cases non-uniform. A common approach to generate non-uniform input PMFs is Huffman shaping, which consists of first approximating the capacity achieving PMF by a sampled Gaussian density and then to calculate the Huffman code of the sampled Gaussian density. The Huffman code is then used as a prefix-free modulation code. This approach showed good results in practice, can however lead to a significant gap to capacity. In this work, a method is proposed that efficiently constructs optimal prefix-free modulation codes for any finite signal constellation with average power constraint in additive noise. The proposed codes operate as close to capacity as desired. The major part of this work elaborates an analytical proof of this property. The proposed method is applied to 64-QAM in AWGN and numeric results are given, which show that, opposed to Huffman shaping, by using the proposed method, it is possible to operate very close to capacity over the whole range of parameters.